{% extends "base.html" %}

{% block title %}首页 - 提示词管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h1 class="mb-4">
            <i class="bi bi-house"></i> 
            欢迎使用提示词管理系统
        </h1>
        <p class="lead text-muted">高效管理您的AI提示词，支持分类、标签、变量替换等功能</p>
    </div>
</div>

<!-- 统计卡片 -->
<div class="row mb-4">
    <div class="col-md-3 mb-3">
        <div class="card stats-card h-100">
            <div class="card-body text-center">
                <i class="bi bi-chat-square-text fs-1 mb-2"></i>
                <h3 class="card-title">{{ stats.total_prompts }}</h3>
                <p class="card-text">总提示词</p>
            </div>
        </div>
    </div>
    <div class="col-md-3 mb-3">
        <div class="card bg-success text-white h-100">
            <div class="card-body text-center">
                <i class="bi bi-check-circle fs-1 mb-2"></i>
                <h3 class="card-title">{{ stats.enabled_prompts }}</h3>
                <p class="card-text">启用提示词</p>
            </div>
        </div>
    </div>
    <div class="col-md-3 mb-3">
        <div class="card bg-info text-white h-100">
            <div class="card-body text-center">
                <i class="bi bi-folder fs-1 mb-2"></i>
                <h3 class="card-title">{{ stats.total_categories }}</h3>
                <p class="card-text">分类数量</p>
            </div>
        </div>
    </div>
    <div class="col-md-3 mb-3">
        <div class="card bg-warning text-white h-100">
            <div class="card-body text-center">
                <i class="bi bi-tags fs-1 mb-2"></i>
                <h3 class="card-title">{{ stats.total_tags }}</h3>
                <p class="card-text">标签数量</p>
            </div>
        </div>
    </div>
</div>

<!-- 快速操作 -->
<div class="row mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-lightning"></i> 
                    快速操作
                </h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3 mb-2">
                        <a href="{{ url_for('add_prompt') }}" class="btn btn-primary w-100">
                            <i class="bi bi-plus-circle"></i> 新建提示词
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="{{ url_for('prompts') }}" class="btn btn-outline-primary w-100">
                            <i class="bi bi-list"></i> 浏览提示词
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="{{ url_for('import_prompts') }}" class="btn btn-outline-success w-100">
                            <i class="bi bi-upload"></i> 导入数据
                        </a>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- 分类统计 -->
<div class="row mb-4">
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-pie-chart"></i> 
                    分类统计
                </h5>
            </div>
            <div class="card-body">
                {% if stats.category_stats %}
                    {% for category_name, category_info in stats.category_stats.items() %}
                        <div class="d-flex justify-content-between align-items-center mb-2">
                            <span>
                                {% if category_info.enabled %}
                                    <i class="bi bi-check-circle text-success"></i>
                                {% else %}
                                    <i class="bi bi-x-circle text-muted"></i>
                                {% endif %}
                                {{ category_name }}
                            </span>
                            <span class="badge bg-primary">{{ category_info.count }}</span>
                        </div>
                        <div class="progress mb-3" style="height: 6px;">
                            <div class="progress-bar" role="progressbar" 
                                 style="width: {{ '%.1f'|format((category_info.count / stats.total_prompts * 100) if stats.total_prompts > 0 else 0) }}%"></div>
                        </div>
                    {% endfor %}
                {% else %}
                    <p class="text-muted">暂无分类数据</p>
                {% endif %}
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-tags"></i> 
                    热门标签
                </h5>
            </div>
            <div class="card-body">
                {% if stats.tag_stats %}
                    {% set sorted_tags = stats.tag_stats.items() | list | sort(attribute=1, reverse=true) %}
                    {% for tag, count in sorted_tags[:10] %}
                        <span class="badge bg-secondary me-1 mb-1">
                            {{ tag }} 
                            <span class="badge bg-light text-dark">{{ count }}</span>
                        </span>
                    {% endfor %}
                {% else %}
                    <p class="text-muted">暂无标签数据</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 系统信息 -->
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="bi bi-info-circle"></i> 
                    系统信息
                </h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <h6>存储信息</h6>
                        <ul class="list-unstyled">
                            <li><strong>数据目录:</strong> {{ stats.storage_stats.data_dir }}</li>
                            <li><strong>提示词文件大小:</strong> {{ "%.2f KB"|format(stats.storage_stats.prompts_file_size / 1024) }}</li>
                            <li><strong>分类文件大小:</strong> {{ "%.2f KB"|format(stats.storage_stats.categories_file_size / 1024) }}</li>
                        </ul>
                    </div>
                    <div class="col-md-4">
                        <h6>功能特性</h6>
                        <ul class="list-unstyled">
                            <li><i class="bi bi-check text-success"></i> 提示词管理</li>
                            <li><i class="bi bi-check text-success"></i> 分类管理</li>
                            <li><i class="bi bi-check text-success"></i> 标签系统</li>
                            <li><i class="bi bi-check text-success"></i> 变量替换</li>
        
                        </ul>
                    </div>
                    <div class="col-md-4">
                        <h6>使用提示</h6>
                        <ul class="list-unstyled">
                            <li>• 使用 <code>{{变量名}}</code> 定义变量</li>
                            <li>• 支持多标签分类管理</li>
        
                            <li>• 支持全文搜索功能</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}